/**
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
*
* @file    register_sensor.c
* @brief   register sensor functions
* @author  HiMobileCam NDK develop team
* @date    2018-2-6
*/
#include <stdio.h>
#include <sensor_comm.h>
#include <sensor_interface_cfg_params.h>
#include "linux_list.h"
#include "mapi_vcap_inner.h"
#include "mapi_comm_inner.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */

static MAPI_LIST_HEAD(s_stSensorCfgHead);

/* Register the sensor configuration, the sensor structure will be placed in the list */
HI_S32 MAPI_SENSOR_Register(HI_MAPI_COMBO_DEV_ATTR_S *pstSensorCfg)
{
    cbb_list_add_tail(&pstSensorCfg->list, &s_stSensorCfgHead);

    return HI_SUCCESS;
}

HI_S32 MAPI_SENSOR_GetConfig(HI_S32 s32SensorType, HI_MAPI_COMBO_DEV_ATTR_S *pstSensorCfg)
{
    HI_MAPI_COMBO_DEV_ATTR_S *pstTmp;

    cbb_list_for_each_entry(pstTmp, &s_stSensorCfgHead, list)
    {
        if (pstTmp->s32SensorType == s32SensorType) {
            *pstSensorCfg = *pstTmp;
            return HI_SUCCESS;
        }
    }

    MAPI_ERR_TRACE(HI_MAPI_MOD_VCAP, "do not have this sensor type:%d !\n", s32SensorType);
    return HI_FAILURE;
}

HI_S32 MAPI_SENSOR_Load(HI_VOID)
{
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "sensor param load begin...\n");

#ifdef SENSOR_IMX477
    CHECK_MAPI_VCAP_RET(SensorImx477Init(), "SensorImx477 param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "SensorImx477 param load success!\n");
#endif

#ifdef SENSOR_IMX377
    CHECK_MAPI_VCAP_RET(SensorImx377Init(), "SensorImx377 param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "SensorImx377 param load success!\n");
#endif

#ifdef SENSOR_IMX290
    CHECK_MAPI_VCAP_RET(SensorImx290Init(), "SensorImx290 param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "SensorImx290 param load success!\n");
#endif

#ifdef SENSOR_IMX335
    CHECK_MAPI_VCAP_RET(SensorImx335Init(), "SensorImx335 param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "SensorImx335 param load success!\n");
#endif

#ifdef SENSOR_IMX458
    CHECK_MAPI_VCAP_RET(SensorImx458Init(), "SensorImx458 param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "SensorImx458 param load success!\n");
#endif

#ifdef SENSOR_IMX307
    CHECK_MAPI_VCAP_RET(SensorImx307Init(), "SensorImx307 param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "SensorImx307 param load success!\n");
#endif

#ifdef SENSOR_GLUX1605B
    CHECK_MAPI_VCAP_RET(SensorGlux1605bInit(), "SensorGlux1605b param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "SensorGlux1605b param load success!\n");
#endif


#ifdef SENSOR_OS05A
    CHECK_MAPI_VCAP_RET(SensorOs05aInit(), "SensorOs05a param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "SensorOs05a param load success!\n");
#endif

#ifdef SENSOR_OS08A10
    CHECK_MAPI_VCAP_RET(SensorOs08a10Init(), "SensorOs08a10 param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "SensorOs08a10 param load success!\n");
#endif

#ifdef SENSOR_OS04B10
    CHECK_MAPI_VCAP_RET(SensorOs04b10Init(), "SensorOs04b10 param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "SensorOs04b10 param load success!\n");
#endif

#ifdef SENSOR_OV12870
    CHECK_MAPI_VCAP_RET(SensorOV12870Init(), "SensorOV12870 param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "SensorOV12870 param load success!\n");
#endif

#ifdef SENSOR_GC2053
    CHECK_MAPI_VCAP_RET(SensorGc2053Init(), "SensorGc2053 param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "SensorGc2053 param load success!\n");
#endif

#ifdef SENSOR_AHD
    CHECK_MAPI_VCAP_RET(SensorAHDInit(), "AHD param load fail!!!");
    MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "AHD param load success!\n");
#endif

#ifdef SENSOR_IMX415
        CHECK_MAPI_VCAP_RET(SensorImx415Init(), "Sensor Imx415 load fail!!!");
        MAPI_INFO_TRACE(HI_MAPI_MOD_VCAP, "Sensor Imx415 load success!\n");
#endif

    return HI_SUCCESS;
}

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */
